/**
 * @author roua_troua
 * 
 * construim visitorul
 * 
 */
package q10.Visitor;

import q10.Operatori.*;
import q10.Arbori.Nod;
import q10.Functii.FunctiiElementare.*;
import q10.Functii.FunctiiTrigonometrice.*;
import q10.Functii.*;

public class ToStringVisitor extends Visitor {
	
	protected String s;
	
	/**
	 * Constructor implicit
	 * 
	 */	
	public ToStringVisitor(){
		this.s = "";
	}
	
	/**
	 * Constructor explicit
	 * @param s
	 */
	public ToStringVisitor(String s){
		this.s = s;
	}
	
	/**
	 * 
	 * @return s String
	 */
	public String getS(){
		return this.s;
	}
	
	/**
	 * 
	 * @param s String
	 * @return 
	 */
	public void setS(String s){
		this.s = s;
	}
	
	/**
	 * 
	 * @param o
	 * @return
	 */
	public void visitare(Operator o){
		if(o.getfStang() != null && o.getfDrept() != null){
			visit(o.getfStang());
			
			String s1 = this.s;
			
			visit(o.getfDrept());
			
			String s2 = this.s;
			s = o.concatTermeni(s1, s2);
		}
	}
	/**
	 * 
	 * @param f
	 * @return
	 */
	public void visitare(Functie f){
		if(f.getfStang() != null && f.getfDrept() != null){
			visit(f.getfStang());
			
			String s1 = this.s;
			
			visit(f.getfDrept());
						
			s = f.concatTermeni(s1);
		}
	}
	/**
	 * @param n Nod
	 * @return
	 */
	public void visit(Nod n){
		if (n.equals(new Plus()))
			visit(n);
		else if (n.equals(new Minus()))
			visit(n);
			else if (n.equals(new Cat()))
				visit(n);
			else if (n.equals(new Produs()))
				visit(n);
		
		if (n.equals(new Sin()))
			visit(n);
		else
			if (n.equals(new Cos()))
				visit(n);
		
		if (n.equals(new Constanta()))
			visit(n);
		else
			if (n.equals(new Necunoscuta()))
				visit(n);
			
	}
	/**
	 * @param Plus p
	 * @return
	 */
	 
	public void visit(Plus p){
		if(p.getfStang() != null && p.getfDrept() != null){
			visit(p.getfStang());
			
			String s1 = this.s;
			
			visit(p.getfDrept());
			
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}
	
	/**
	 * @param Cat ct
	 * @return
	 */
	public void visit(Cat c){
		if(c.getfStang() != null && c.getfDrept() != null){
			visit(c.getfStang());
			
			String s1 = this.s;
			
			visit(c.getfDrept());
			
			String s2 = this.s;
			s = c.concatTermeni(s1, s2);
		}
	}
	
	/**
	 * @param Minus m
	 * @return
	 */
	public void visit(Minus m){
		if(m.getfStang() != null && m.getfDrept() != null){
			visit(m.getfStang());
			
			String s1 = this.s;
			
			visit(m.getfDrept());
			
			String s2 = this.s;
			s = m.concatTermeni(s1, s2);
		}
	}	
	
	/**
	 * @param Produs pr
	 * @return
	 */
	public void visit(Produs pr){
		if(pr.getfStang() != null && pr.getfDrept() != null){
			visit(pr.getfStang());
			
			String s1 = this.s;
			
			visit(pr.getfDrept());
			
			String s2 = this.s;
			s = pr.concatTermeni(s1, s2);
		}
	}

	/**
	 * @param Constanta ct
	 * @return
	 */
	public void visit(Constanta ct){
		this.s = Double.toString(ct.getCt());
	}
	
	/**
	 * @param Necunoscuta n
	 * @return
	 */
	public void visit(Necunoscuta n){
		this.s = "x";
	}
	
	/**
	 * @param Sin sin
	 * @return
	 */
	public void visit(Sin sin){
		if(sin.getfStang() != null && sin.getfDrept() != null){
			visit(sin.getfStang());
			
			String s1 = this.s;
			
			visit(sin.getfDrept());
						
			s = sin.concatTermeni(s1);
		}
	}
	
	/**
	 * @param Necunoscuta n
	 * @return
	 */
	public void visit(Cos cos){
		if(cos.getfStang() != null && cos.getfDrept() != null){
			visit(cos.getfStang());
			
			String s1 = this.s;
			
			visit(cos.getfDrept());
						
			s = cos.concatTermeni(s1);
		}
	}
	
	/**
	 * @param Tg tg
	 * @return
	 */
	public void visit(Tg tg){
		
	}
	
	/**
	 * @param Ctg ctg 
	 * @return
	 */
	public void visit(Ctg ctg){
		
	}
	
}
